package com.emellend.api.progressbar;

import com.emellend.api.R;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class ProgressBar3 extends Activity implements OnClickListener {
	
	private ProgressDialog mDialog1;
	private ProgressDialog mDialog2;
	
	
	private static final int DIALOG1_KEY = 0;
	private static final int DIALOG2_KEY = 1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.progressbar_3);
		addListener();
	}

	private void addListener() {
		this.findViewById(R.id.showIndeterminate).setOnClickListener(this);
		this.findViewById(R.id.showIndeterminateNoTitle).setOnClickListener(this);
	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.showIndeterminate:
			showDialog(DIALOG1_KEY);
			break;

		case R.id.showIndeterminateNoTitle:
			showDialog(DIALOG2_KEY);
			break;
		}
	}
	
	@Override
	protected Dialog onCreateDialog(int id) {
		switch (id) {
		case DIALOG1_KEY:
			return createProgressDialog("Indeterminate", "Please wait while loading...");
		case DIALOG2_KEY:
			return createProgressDialog(null, "Please wait while loading...");
		}
		return null;
	}

	private Dialog createProgressDialog(String title,String message) {
		ProgressDialog dialog=new ProgressDialog(this);
		if (title!=null&&!"".equals(dialog)) {
			dialog.setTitle(title);
		}
		if (message!=null&&!"".equals(message)) {
			dialog.setMessage(message);
		}
		dialog.setIndeterminate(true);
		dialog.setCancelable(true);
		return dialog;
	}

}
